﻿using System;
using System.Collections;
using System.Web.UI.WebControls;
using ASPNETVN.PORTAL.Components.Helpers;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Components.Configuration.Settings;
using ASPNETVN.PORTAL.Components.UI.DataTypes;

namespace ASPNETVN.PORTAL.Modules.ADVERTISEMENT
{
    public enum ModulePages
    {
        Item,
        ItemTopBanner,
        ItemBottomBanner, 
        VerticalMarquee,
        HorizontalMarquee,
        HorizontalStatic,
        ImageSlideshow2
    }

    public partial class Main : PortalModuleControl
    {
        public Main()
        {
            // Define an Array List
            ArrayList list = new ArrayList();
            list.Add(new ListItem("Item", "Item"));
            list.Add(new ListItem("ItemTopBanner", "ItemTopBanner"));
            list.Add(new ListItem("ItemBottomBanner", "ItemBottomBanner"));
            list.Add(new ListItem("ImageSlideshow2", "ImageSlideshow2"));
            list.Add(new ListItem("HorizontalMarquee", "HorizontalMarquee"));
            list.Add(new ListItem("HorizontalStatic", "HorizontalStatic"));
            list.Add(new ListItem("VerticalMarquee", "VerticalMarquee"));

            ModuleSettingItem itemSetting = new ModuleSettingItem(new CustomListDataType(list, "Text", "Value"));
            itemSetting.Value = "Item";
            itemSetting.Name = "Hình thức hiển thị";
            itemSetting.Description = "Hình thức hiển thị";
            itemSetting.SortOrder = 1;
            this.BaseSettings.Add("DisplayStyle", itemSetting);

            itemSetting = new ModuleSettingItem(new StringDataType());
            itemSetting.Value = "1";
            itemSetting.Name = "Số cột hiển thị";
            itemSetting.Description = "Số cột hiển thị";
            itemSetting.SortOrder = 1;
            this.BaseSettings.Add("Columns.Count", itemSetting);

            //itemSetting = new ModuleSettingItem(new StringDataType());
            //itemSetting.Value = "3000";
            //itemSetting.Name = "Số giây lật hình (1 giây = 1000 mili giây)";
            //itemSetting.Description = "Số giây lật hình (1 giây = 1000 mili giây)";
            //itemSetting.SortOrder = 1;
            //this.BaseSettings.Add("Advertise.S", itemSetting);
        }

        private void LoadModulePage()
        {
            const string basePath = "~/Modules/ASPNETVN.PORTAL.Modules.ADVERTISEMENT/";
            ModulePages page = (ModulePages)Enum.Parse(typeof(ModulePages), this.Settings["DisplayStyle"].ToString(), true);
            string src = string.Format("{0}Controls/{1}.ascx", basePath, page);
            ModulePage ctl = (ModulePage)this.LoadControl(src);
            ctl.ParentControl = this;
            this.divContent.Controls.Add(ctl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.LoadModulePage();
            this.ModuleTitle.AddUrl = HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, 0, "AddEditItem");
            this.ModuleTitle.ManagerUrl = HttpUrlBuilder.BuildAddEditUrl(ModuleID, 0, "Management");
        }
    }
}